﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext;
using Coolite.Ext.Web;
public partial class Company_Modify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            Store2Databind();
        } 
    }
    protected void DeleteRow(object s, AjaxEventArgs e)
    {
        string id = e.ExtraParams["id"].ToString();
        
        CxCompanyPingJium.Delete("id", id);
        Err.Warning("删除成功！", MessageBox.Icon.NONE);
        Store1.DataBind();
        Clear();
    }
    protected void RowSelect(object s, AjaxEventArgs e)
    {
        string id = e.ExtraParams["id"].ToString();
        tfid.Value = id;
        Query q = new Query(CxCompanyPingJium.Schema);
        q.AddWhere("id", id);
        IDataReader dr = q.ExecuteReader();
        if (dr.Read())
        {
            tfcompanyid.Text = dr["companyid"].ToString();
            tfcompanyname.Text = dr["companyname"].ToString();
            tfunfee_time.Value = dr["unfee_time"].ToString() == "" ? "" : dr["unfee_time"].ToString();
            tfunfee_cash.SetValue(dr["unfee_cash"].ToString());
             
            tfthief_time1.Value = dr["thief_time1"].ToString() == "" ? "" : dr["thief_time1"].ToString();
            tfthief_time2.Value = dr["thief_time2"].ToString() == "" ? "" : dr["thief_time2"].ToString();
            tfuncoop_peak_time.Value = dr["uncoop_peak_time"].ToString() == "" ? "" : dr["uncoop_peak_time"].ToString();
            tfuncoop_peak_detail.Text = dr["uncoop_peak_detail"].ToString();
            tfuncoop_limit_time.Value = dr["uncoop_limit_time"].ToString() == "" ? "" : dr["uncoop_limit_time"].ToString();
            tfuncoop_limit_detail.Text = dr["uncoop_limit_detail"].ToString();
            tfuncoop_others.Text = dr["uncoop_others"].ToString();
            tfdept_master_id.SetInitValue(dr["dept_master_id"].ToString());
            tfdept_master_remark.Text = dr["dept_master_remark"].ToString();
        }
    }
    protected void SubForm(object s, AjaxEventArgs e)
    {
        if (tfid.Value.ToString() == "") { Err.Warning("请从左侧列表选择一条记录！", MessageBox.Icon.WARNING); return; }
        CxCompanyPingJium cx = new CxCompanyPingJium("id",tfid.Value.ToString());
        if (tfunfee_time.Value.ToString() != "0001/1/1 0:00:00" && tfunfee_time.Value.ToString()!="")
        {
            cx.UnFeeTime = DateTime.Parse(tfunfee_time.Value.ToString());
        }
        cx.UnFeeCash = int.Parse(tfunfee_cash.Value.ToString());
        cx.UnFeeDetail = tfunfee_detail.Text;
        if (tfthief_time1.Value.ToString() != "0001/1/1 0:00:00" && tfthief_time2.Value.ToString() != "0001/1/1 0:00:00" && tfthief_time1.Value.ToString()!=""&& tfthief_time2.Value.ToString() != "")
        {
            cx.ThiefTime1 = DateTime.Parse(tfthief_time1.Value.ToString());
            cx.ThiefTime2 = DateTime.Parse(tfthief_time2.Value.ToString());
        }
        cx.ThiefCash = int.Parse(tfthief_cash.Value.ToString());
        cx.ThiefDetail = tfthief_detail.Text;
        if (tfuncoop_peak_time.Value.ToString() != "0001/1/1 0:00:00" && tfuncoop_peak_time.Value.ToString() !="")
        {
            cx.UnCoopPeakTime = DateTime.Parse(tfuncoop_peak_time.Value.ToString());
        }
        cx.UnCoopPeakDetail = tfuncoop_peak_detail.Text;
        if (tfuncoop_limit_time.Value.ToString() != "0001/1/1 0:00:00"&& tfuncoop_limit_time.Value.ToString() != "")
        {
            cx.UnCoopLimitTime = DateTime.Parse(tfuncoop_limit_time.Value.ToString());
        }
        cx.UnCoopLimitDetail = tfuncoop_limit_detail.Text;
        cx.UnCoopOthers = tfuncoop_others.Text;
        cx.DeptMasterStatus = 0;
        cx.ManagerStatus = 0;
        cx.OtherMasterId = 0;
        cx.OtherMasterStatus = 0;
        cx.Save();
        Err.Warning("修改提交成功！",MessageBox.Icon.WARNING);
        

    }
    protected void Clear()
    {
        tfcompanyid.Text = "";
        tfcompanyname.Text = "";
        tfunfee_time.Clear();
        tfunfee_cash.Clear();
        tfthief_time1.Clear();
        tfthief_time2.Clear();
        tfuncoop_peak_time.Clear();
        tfuncoop_peak_detail.Text = "";
        tfuncoop_limit_time.Clear();
        tfuncoop_limit_detail.Text = "";
        tfuncoop_others.Text = "";
        tfdept_master_id.Reset();
        tfdept_master_remark.Text = "";
    }
    protected void Store2Databind()
    {
        Query q = new Query(CxUserBase.Schema);
        q.SetSelectList("username,uid");
        q.AddWhere("depid", Cookies.getCookies("cdeptid"));
        q.AddWhere("levelid", 1);
        Store2.DataSource = q.ExecuteDataSet();
        Store2.DataBind();
    }
}
